using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Collections;
using System.Data;
using System.IO;
using MyClever.Lib;

namespace MyClever.DefaultPlugins
{
    public class DeleteDirectoriesPlugin : MissionPlugin
    {
        [Package(Direction.Input, "Defines the directories, you like to delete.")]
        enum DeleteDirectories
        {
            [Column(typeof(string), "The directory you like to delete?")]
            DirectoryName,
            [Column(typeof(bool), "if true, all directories, subdirectories, and files in path will removed.",
                DefaultValue="true")]
            DeleteRecursive
        }

        [Plugin(PluginDevStatus.Production, "Deletes the given directories.")]
        public DeleteDirectoriesPlugin()
        {
        }

        public override void Initialize()
        {
            
            //This is the first Function called by the host...
            //Put anything needed to start with here first
        }

        public override void Dispose()
        {
            //Put any cleanup code in here for when the program is stopped
        }

        /// <summary>
        /// Generate new Source-content.
        /// </summary>
        protected override void Work()
        {
            DataTableReader deleteDirectories = this.GetDataReader(typeof(DeleteDirectories));
            while (deleteDirectories.Read())
            {
                this.AddNewLoggingMessage(typeof(DeleteDirectories), String.Format("delete:{0}", deleteDirectories[DeleteDirectories.DirectoryName.ToString()].ToString()));

                Directory.Delete(deleteDirectories[DeleteDirectories.DirectoryName.ToString()].ToString(), Convert.ToBoolean(deleteDirectories[DeleteDirectories.DeleteRecursive.ToString()]));
            }
        }
    }
}
